package cn.edu.scau.daoImpl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import cn.edu.scau.dao.ColumnsDao;
import cn.edu.scau.entity.Columns;

/**
 * 栏目Dao接口实例
 * @author Administrator
 *
 */
@Repository("columnsDaoImpl")
public class ColumnsDaoImpl extends BaseDaoImpl<Columns> implements ColumnsDao {
	
	/**
	 * 根据父级栏目的id展示所有的子级栏目
	 * @param parentColumnId 父级栏目的id
	 * @return 所有的子级栏目
	 */
	public List<Columns> showAllChildColumns(Serializable parentColumnId) {
		Session session = getSessionFactory().openSession();
		Query query = session.createQuery("select co from Columns co where co.parentId = ?0 order by co.order asc");
		query.setParameter("0", parentColumnId);
		List<Columns> list = query.list();
		session.flush();
		session.close();
		return list;
	}

	/**
	 * 展示所有父级栏目id为0的栏目
	 * @return  所有父级栏目id为0的栏目
	 */
	public List<Columns> showAllFatherColumns() {
		Session session = getSessionFactory().openSession();
		Query query = session.createQuery("select co from Columns co where co.parentId = 0 order by co.order asc");
		List<Columns> list = query.list();
		session.flush();
		session.close();
		return list;
	}

}
